package com.mystudy.design_patterns.Singleton;

/**
 * @program: infoalgorithm
 * @description: 懒汉式单例模式
 * @author: zhouzhilong
 * @create: 2019-02-18 15:42
 **/
public class SingletonLazy {
    private static SingletonLazy sl = null;

    private SingletonLazy() {

    }

    //synchronized是用来在高并发的情况下仍然保持只有一个对象产生，以维护线程安全
    public static synchronized SingletonLazy getInstance() {
        if (sl == null) {
            sl = new SingletonLazy();
        }
        return sl;
    }

}
